#!/usr/bin/env node 

const {program}=require('commander');
const inquirer=require('inquirer');
const fs=require('fs');
const {version}=require('./package.json');
let path=require('path')

let pormptList=[
    {
        type:'input',
        name:'name',
        message:'project name',
        default:path.parse(__dirname).name
    },
    {
        type:'input',
        name:'version',
        message:'version',
        default:'1.0.0'
    },
    {
        type:'input',
        name:'author',
        message:'author',
    },
    {
        type:'input',
        name:'main',
        message:'entry point',
        default:'index.js'
    },
    {
        type:'input',
        name:'keywords',
        message:'keywords',
        
    },
]
// 定义action处理函数
const actionHandle=async(options)=>{
    // console.log(options);
   let answers=await inquirer.prompt(pormptList);
   console.log(answers);
   fs.writeFileSync('./package-test.json',JSON.stringify(answers))
}
// 定义指令
program
    .command('init')
    .option('-y')
    .description('create a package-test.json')
    .action(actionHandle)

// 解析进程参数
program.version(version).parse(process.argv)